package com.lzhsite.technology.designPattern.strategy.GuessDemo;

public class Hand
{
    public static final int ONE_VALUE = 0;
    public static final int TWO_VALUE = 1;
    public static final int Three_VALUE = 2;

    public static final Hand[] HANDS =
            {
                    new Hand(ONE_VALUE),
                    new Hand(TWO_VALUE),
                    new Hand(Three_VALUE)
            };

    private static final String[] names = {"石头", "剪子", "布"};

    private int handValue;

    private Hand(int handValue)
    {
        this.handValue = handValue;
    }

    public static Hand getHand(int handValue)
    {
        return HANDS[handValue];
    }

    public boolean isWin(Hand target)
    {
        return (judgeHand(target) == 1);
    }

    /**
     * 数据越小越的赢,最后一个和第一个比较除外
     * @param target
     * @return
     */
    private int judgeHand(Hand target)
    {
        if (this.handValue == target.handValue)
        {
            return 0;
        } else if ((this.handValue + 1) % 3 == target.handValue)
        {
            return 1;
        } else
        {
            return -1;
        }
    }

    public boolean isLose(Hand target)
    {
        return (judgeHand(target) == -1);
    }

    public String toString()
    {
        return names[handValue];
    }
}
